home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Documents / PressReleases93 / 07July / Shopper.txt < prev    next >
Text File  |  1995-06-12  |  19KB  |  343 lines

  1.  
  2.  
  3. Item    4945697                 93/07/22        13:10 
  4. From:   CGEIGER@NEXT.COM@INET#          Internet Gateway 
  5. Subject: Taking the NEXTSTEP:Excerpt from Computer Shopper
  6.  
  7. Hello User Groups,
  8.  
  9. Here is a great review on NEXTSTEP from the Computer Shopper...
  10.  
  11. Conrad Geiger
  12.  
  13.  
  14. ____________________________________________________ 
  15. COMPUTER SHOPPER
  16.  
  17. Tech Section Development Tools
  18.  
  19. Taking the NextStep, Part One By Bruce Graves July 1993 Page 551
  20.  
  21. The first time I ran into NeXT computers (and Steve Jobs, NeXT's CEO, almost
  22. literally ran into me) was in 1989, my senior year at Cornell University. 
  23. Jobs had just given a presentation about NeXT computers and was walking out of
  24. Carpenter Hall, one of Cornell's engineering buildings.  I was hobbling in the
  25. door on crutches, having injured myself that morning playing basketball.  Jobs
  26. was so engaged in a conversation that he didn't notice me at all, and only his
  27. companion's quick reaction saved me from a second crash to the floor that day.
  28.  
  29. Four years later, a NeXT machine (on loan from NeXT) dominates my office.  Its
  30. 17-inch, flat-screen color display dwarfs my PC's 14-inch monitor, while its
  31. sleek, two-and-a-half-inch-high CPU case makes my PC look like a mini-
  32. computer.  But don't plan on purchasing your own NeXT system--NeXT is getting
  33. out of the hardware business.  Do keep your eyes open for NeXTSTEP, NeXT's
  34. evolutionary--and in some ways revolutionary--operating environment for 486 or
  35. higher PC's, expected sometime this summer.
  36.  
  37. But what is NeXTSTEP?  How does it differ from an environment like Microsoft
  38. Windows, especially from a developer's perspective?  And do all the
  39. differences represent steps forward?  To find out, I experimented with the
  40. system for a little over two months, them attended a week-long class called
  41. "Programming NeXT Computers," affectionately nicknamed Dev-Camp.  The course
  42. is sponsored by NeXT and is designed to introduce developers to NeXTSTEP and
  43. the concepts of object-oriented programming in general.
  44.  
  45. It turns out that complete answers to my original questions, never mind all
  46. the new ones that came up as I learned about NeXTSTEP, would fill hundreds of
  47. pages.  Almost every aspect of NeXTSTEP, from its interface to its suite of
  48. development tools, is unique. As a result, I've split this article into two
  49. parts.  This month, we'll take a look at what it's like to use NeXTSTEP, how
  50. its underlying design is different from environments like Microsoft Windows,
  51. and why it's so easy to create basic NeXTSTEP applications.
  52.  
  53. Next month, we'll dig a little deeper and examine how NeXTSTEP displays and
  54. prints graphics and text.  We'll also see how simple it is to take advantage
  55. of "Distributed Objects," which allow programs to transparently access data
  56. and code on any NeXTSTEP machine on a network.  Hopefully, a brief look at
  57. topics like these will give you a feel for why some developers, once they've
  58. played with NeXTSTEP, are completely hooked.  On the other hand, we'll also
  59. look at a few issues that might explain why, despite all of its strength,
  60. NeXTSTEP doesn't dominate the marketplace.
  61.  
  62. NEXTSTEP
  63.  
  64. NeXTSTEP is an operating environment that consists of a graphical user
  65. interface (GUI, pronounced "gooey") that sits on top of Mach, an operating
  66. system that is upwardly compatible with Unix 4.3BSD. In addition to standard
  67. Unix features, such as pre-emptive multitasking, Mach also supports multiple
  68. threads, memory-mapped files, message-based interprocess communication, and a
  69. host of other facilities.  Windows NT, which supports most of these features,
  70. too, was heavily influenced by Mach, and future version of IBM's OS/2 are
  71. likely to be based on it.
  72.  
  73. Figure 1 displays part of a typical NeXTSTEP screen, also known as the
  74. workspace.  The file Viewer, in the center of the image, allows you to
  75. navigate the Unix directory structure, manipulate files and directories, and
  76. launch applications.  The center of the File Viewer shows the current
  77. directory hierarchy as a series of icons, and the files in each of these
  78. directories are listed directly below them.  The top of the File Viewer is
  79. called the shelf, where you can place frequently used files or directory
  80. folders for quick access.  To place an item on the shelf, you drag its icon
  81. from the row in the center and drop it on the shelf.
  82.  
  83. On the right side of the screen is the application dock, where you can place
  84. frequently used applications icons.  Placing an application icon on the dock
  85. is just like placing it on the File Viewer's shelf; you drag it from the File
  86. Viewer and drop it on the dock.  Consistency like this one of NeXTSTEP's
  87. strengths.  Once you figure out how to do something in one context, you can
  88. usually figure out how to accomplish the same thing anywhere--without reaching
  89. for a manual.
  90.  
  91. NeXTSTEP menus are vertical lists that can be displayed anywhere in the
  92. workspace, as opposed to drop-down menus that appear at the top of each
  93. program's main window.  Applications usually take advantage of hierarchical
  94. menus, where clicking on one menu entry display a submenu to the right of the
  95. original.  If you use the entries in a particular sub-menu frequently, you can
  96. "tear it off" and place it anywhere on the screen.  Only the active
  97. application's menus are visible; NeXTSTEP hides background applications' menus
  98. to save screen space.
  99.  
  100. NeXTSTEP windows differ just enough from Microsoft Windows' windows to drive
  101. you crazy if you have to  switch between them frequently. Apparently to avoid
  102. legal issues, NeXT placed the minimize button in the upper left corner of a
  103. window's title bar and put the close button in the upper right corner, exactly
  104. the opposite of Windows conventions (there is no such thing as a maximize
  105. button under NeXTSTEP).  Along the same lines, verticle scroll bars appear on
  106. the left side of windows, and the up and down arrows are grouped together at
  107. the bottom of the scroll bar.
  108.  
  109. Keyboard usage is different under NeXTSTEP, too.  NeXT doesn't rely on
  110. numbered function keys at all, and they've added a special Command key
  111. (simulated by a keystroke combination on PCs) that's dedicated specifically to
  112. keyboard shortcuts.  For example, Command-s always means "Save," while Command-
  113. q always means "Quit." Compare this to keyboard shortcuts under Microsoft
  114. Windows, where Shift-F12 saves files in Microsoft Windows, for Windows,
  115. invokes a settings dialog in Borland's Quattro Pro, and probably does
  116. something completely different in tens of other applications.
  117.  
  118. Unlike Windows, which is designed to operate with or without a pointing
  119. device, NeXTSTEP always assumes that a mouse is available and relies on it
  120. heavily.  For example, there's no easy way to access menu entries that don't
  121. have Command-based accelerators assigned to them without using the mouse.  You
  122. can't jump from one application to the next from the keyboard; again, you must
  123. reach for the mouse. And when NeXTSTEP's equivalent of an OK/Cancel dialog
  124. appears, you can hit Enter to accept it, but only a mouse click will cancel
  125. it. Hitting Escape only produces a beep.
  126.  
  127. These are only a few of the cosmetic differences between NeXT-STEP and other
  128. GUIs.  Their significance varies, depending on what you're used to and how
  129. often you have to switch back and forth between different environments. 
  130. Still, they illustrate a philosophy that pervades NeXTSTEP.  Its designers
  131. favored elegance and simplicity and ignored existing conventions that they
  132. didn't feel made sense.  This is important to users, but it's even more
  133. important to developers.
  134.  
  135.  
  136. AN OO GUI?
  137.  
  138. GUIs like Microsoft Windows started as a group of interface elements and a set
  139. of API functions to manipulate them.  Since object-oriented programming (OOP)
  140. has surged in popularity, various vendors, including Microsoft, have strapped
  141. applications frameworks on top of existing GUIs.  These frameworks encapsulate
  142. the details of the underlying GUIs and allow programmers to view them from an
  143. object-oriented perspective.  However, the GUIs themselves were mostly written
  144. in C, which doesn't support OOP directly.
  145.  
  146. NeXTSTEP is different.  It isn't a set of stand-alone interface elements, and
  147. it doesn't have a traditional API. Instead, NeXTSTEP is a hierarchy of
  148. Objective C classes.  In effect, it is a GUI and an application framework
  149. rolled into one. Unlike other GUIs, which allow you to write applications in
  150. any language that can call traditional C or Pascal functions, NeXTSTEP
  151. requires that the parts of an application that interface with the GUI directly
  152. be written in Objective C (though other parts of the application can be
  153. written in other languages, such as C++).
  154.  
  155.  
  156. A SAMPLE PROGRAM
  157.  
  158. To get a feel for some of the advantages of a truly object-oriented GUI, we'll
  159. create a very simple NeXTSTEP program called Side, which will display a window
  160. that contains a slider and a text field.  The position of the slider will
  161. range from zero (at it's far left) to 100 (at its far right).  As you move the
  162. slider back and forth, the text field will display a number corresponding to
  163. its position.  If you enter a number in text field and hit Enter, the slider
  164. will position itself appropriately.  But here's where it gets interesting:  We
  165. won't write a single line of code.
  166.  
  167. The first step in creating Slide is to run an application called Project
  168. Builder, or PB, and create a new project.  PB is similar in many respects to
  169. Borland's integrated Development Environment and Microsoft's Programmer's
  170. Workbench for Windows.  It keeps track of all of your program's components and
  171. automatically creates a makefile that it uses to build your application.
  172.  
  173. Once you've created a new Slide project, you can double-click on one of the
  174. files that PB creates for you automatically, SLIDE.NIB.  The NIB extension
  175. stands for NeXT Interface Builder (IB), which is where most of the work on an
  176. application's interface takes place.  Double-clicking on a NIB file launches
  177. IB automatically. PB is still running in the background.
  178.  
  179. Interface Builder lets you to lay out interface elements, such as windows and
  180. controls.  When you open a new project in IB, it automatically creates a main
  181. window and a menu with a few basic entries, such as Quit, for your
  182. application.  IB also displays a window that contains a palette of common
  183. controls.  Adding a slider and a text display to the Slide program is as
  184. simple as dragging copies of them from the palette and dropping them in the
  185. main window--similar to Visual Basic.
  186.  
  187. After you place a control in the main window, you can hit Command-1 to bring
  188. up an inspector window.  Inspector windows display information about the
  189. object that is currently selected and allow you to modify some of its
  190. attributes.  For the slider, the inspector displays its minimum value (which
  191. defaults to 0), its maximum value (which defaults to 1), and its current
  192. position (a number between 0 and 1).  You can change these values by entering
  193. new numbers in the appropriate fields.  We'll change the maximum value from 1
  194. to 100 and set its current position to 0.
  195.  
  196.  
  197. ACTION!
  198.  
  199. To try out an interface, you simply hit Command-r, the keyboard shortcut for
  200. Test interface.  The main window, which contains a slider and a text field,
  201. appears, along with the program's menu. You can move the slider, but it
  202. doesn't update the text field. Similarly, you can enter a number in the text
  203. file, but it won't affect the slider.  Selecting Quit from the application's
  204. menu returns you to IB.  Under most other GUIs, it would be time to save the
  205. interface and write some code to connect the two objects; NeXTSTEP is
  206. different.
  207.  
  208. In IB, holding down the Ctrl key and clicking on the slider causes a thin
  209. black line to appear.  One end of the line is attached to the slider, and the
  210. other end follows the mouse cursor. Moving the cursor over the text field and
  211. releasing the mouse button causes the line to "connect" the slider to the text
  212. field. (see Figure 2).  When this connection appears, the inspector window
  213. (which we used to set the slider's range, above) changes.  It now lists two
  214. columns of text, one called Outlets and the other called Actions.  For you to
  215. understand what the entries in these columns refer to, it's necessary to
  216. explain a little about Objective C.
  217.  
  218.  
  219. OBJECTIVE C
  220.  
  221. Objective C is an extension to standard C that provides object-oriented
  222. capabilities.  To do this, Objective C allows you to define classes and adds a
  223. mechanism that allows you to send messages to class instances, also known as
  224. objects.  Objective C also adds one new variable type, id, which is a pointer
  225. that can point to any type of object.  These are really the only changes that
  226. Objective C makes to the C language.
  227.  
  228. At first glance, Objective C appears to add fewer capabilities than C++ does.
  229. This is true in some areas, since C++ was designed to be a "better C," while
  230. Objective C was only intended to add object-oriented features.  However, in
  231. parts of the object-oriented arena, Objective C extends C further than C++.
  232. Specifically, Objective C provides a capability called "dynamic binding" that
  233. C++ doesn't fully support.
  234.  
  235. In this context, dynamic binding means that the compiler doesn't have to know
  236. everything about the objects that messages are being sent to.  For example, in
  237. Objective C, the expression anObject aMessage; sends a message to an object. 
  238. Sending a message to an object is similar to calling a C++ object's member
  239. function. Its analog in C++ would be anObject->aMemberFunction();.
  240.  
  241. The important difference between the two, however, is that a C++ compiler
  242. needs to know something about anObject's type.  On the other hand, an
  243. Objective C compiler doesn't care what type of object anObject is.  All the
  244. decision making can be delayed until run time. This adds an incredible degree
  245. of flexibility, as you'll see shortly.
  246.  
  247. WHAT DYNAMIC BINDING DOES FOR YOU
  248.  
  249. How does any of this relate to the Outlets and Actions columns in IB's
  250. inspector window?  As you'll recall, the line that we drew comes from the
  251. slider and goes to the text field.  These objects are actually instances of
  252. two NeXTSTEP Objective C classes, called Slider and TextField, respectively. 
  253. Both descend from another NeXTSTEP class Control.
  254.  
  255. The Control class (and hence all its descendants) contains a member variable
  256. called target which is of type id (recall that id is a pointer to any type of
  257. Objective C object).  When you connect two objects in IB, the object that you
  258. draw the line from displays all of its id fields in the Outlets column.  This
  259. allows you to specify which one of its id fields (target in this case) should
  260. point to the object that you connected the line to (the text field).  You
  261. choose the proper id field by clicking on its entry in the Outlets column.
  262.  
  263. What about the Actions column, however?  The object that you connect the line
  264. to (the text field) displays a list of its methods (analogous in many ways to
  265. C++ member functions) in the Actions column.  In this case, this allows us to
  266. specify which message should be sent from the slider to the text field
  267. whenever the slider is moved.  The text field displays a list of seven
  268. methods, and the one we're interested in is called takeDoubleValue.
  269.  
  270. All of this is much simpler to do than it is to explain. Once we've drawn the
  271. line from the slider to the text field, we can click on the target entry in
  272. the Outlets column and the takeDoubleValue entry in the Actions column.  It's
  273. just as easy to connect the text field to the slider.  We simply draw a line
  274. from the text field to the slider, once again clicking on the target entry in
  275. the Outlets column and the takeDoubleValue entry in the Actions column.
  276.  
  277. After making these connections, you can hit Command-r again (to test the
  278. interface) and see what happens.  Amazingly enough, moving the slider
  279. automatically updates the contents of the text field, and entering a number in
  280. the text field and hitting return moves the slider!  But how does this work
  281. without any code?
  282.  
  283. What's really going on here is that whenever you move the slider, it examines
  284. its target field.  When it discovers that it points to something (the text
  285. field), it sends a message (takeDoubleValue) to that object and passes a
  286. pointer to itself as a parameter. The text field's takeDoubleValue method uses
  287. the pointer that it receives to ask the slider (the object that sent the
  288. message) what its current position is, then displays that value in the text
  289. field.
  290.  
  291. Interface Builder doesn't limit you to send messages between NeXTSTEP
  292. interface elements.  You can use IB to connect any type of object to any other
  293. type of object.  For example, you could connect a slider to an object of your
  294. own that takes a number and multiplies it by two.  You could then connect this
  295. object to a text field, where it could display its results.  You would have to
  296. write a little bit of code to create an object of your own--about three lines'
  297. worth.
  298.  
  299.  
  300. BACK TO PROJECT BUILDER
  301.  
  302. Until now, we've done everything from within the Interface Builder. To produce
  303. a stand-alone application, you save the work you've done in IB (which updates
  304. the NIB file) and return to the Project Builder.
  305.  
  306. Hitting the Build button causes PB to execute the makefile that it has
  307. constructed; the result is a stand-alone version of the Slide program.
  308.  
  309. But how does your application work without any handwritten code?  Instead of
  310. requiring you to write the routines that create and display you inter-face
  311. objects manually, NeXTSTEP handles the details for you.  The DevCamp
  312. instructor drew an excellent analogy: He described the NIB file as a
  313. collection of "freeze-dried objects."   When you execute you application,
  314. NeXTSTEP loads the associated NIB file and, in effect, "adds water."  As a
  315. result, all the objects that you laid out in IB come to life automatically.
  316.  
  317.  
  318.  
  319. UNTIL NEXT MONTH
  320.  
  321. There's a lot more to writing simple NeXTSTEP programs, never mind full-
  322. fledged applications, than we've covered here.  For example, nothing that
  323. we've seen so far has shown us how to write a program that doesn't rely on
  324. built-in interface objects like sliders and text fields.  What if you want to
  325. draw a line, or write a NeXTSTEP version of the famous "hello, world" program?
  326.  
  327. Next month, we'll see how to display graphics and text in a window, and why
  328. every application automatically inherits the ability to print or FAX any of
  329. its images--once again, without writing any code.  And we'll look at a few
  330. additional topics that will make you ask, "Why hasn't Microsoft done this
  331. under Windows?"
  332.  
  333.  
  334.  
  335. Figure 1:  A typical Nextstep screen, also known as the workspace. The file
  336. viewer, in the center of the image, allows you to navigate the Unix directory
  337. structure.
  338.  
  339. Figure 2:  The Interface Builder in action.  Moving the cursor over the text
  340. field and releasing the mouse button causes the line to "connect" the slider
  341. to the text field.
  342.  
  343. =END=